package testsuite_homepage;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

public class POMLoginForm {

	 

		private final WebDriver driver;

		private By loginformLocator = By.id("form-login");

		private By usernameLocator = By.id("modlgn_username");

		private By passwordLocator = By.id("modlgn_passwd");

		private By loginButtonLocator = By.name("Submit");

		public POMLoginForm(WebDriver driver) {

			this.driver = driver;

			if (!driver.findElement(loginformLocator).isDisplayed()) {

				throw new IllegalStateException("There is no login form");

			}

		}

		public POMLoginForm typeUsername(String username) {

			driver.findElement(usernameLocator).sendKeys(username);

			return this;

		}

		public POMLoginForm typePassword(String password) {

			driver.findElement(passwordLocator).sendKeys(password);

			return this;

		}

		public SuccessLoginPage submitLogin() {

			driver.findElement(loginButtonLocator).submit();

			return new SuccessLoginPage(driver);

		}

		public FalseLoginPage submitFalseLogin() {

			driver.findElement(loginButtonLocator).submit();

			return new FalseLoginPage(driver);

		}

		public SuccessLoginPage loginAs(String username, String password) {

			typeUsername(username);

			typePassword(password);

			return submitLogin();

		}

	}

